#include "Thread.hpp"
#include <iostream>
#include <unistd.h>
#include <vector>
using namespace ThreadModule;

void Task(std::string& name)
{
    while (true)
    {
        std::cout << name << ", is running..." << std::endl;
        sleep(1);
    }
}

const int num = 5;// 创建线程的数量

int main()
{
    std::vector<Thread<std::string>> tids;
    // 创建
    for(int i = 0; i < num; i++)
    {   
        std::string name = "thread_" + std::to_string(i+1);
        Thread<std::string>* t = new Thread<std::string>(name, Task);
        tids.emplace_back(name, Task);
    }
    sleep(3);

    // 启动
    for(auto& t : tids)
        t.start();
    sleep(10);

    // 终止
    for(auto& t : tids)
        t.stop();
    
    // 等待
    for(auto& t : tids)
        t.join();


    return 0;
}